Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX release] ArrayProxy#content should not be a computed property #12860

Closed
wants to merge 1 commit into from

Conversation

mmun
Copy link
Member

@mmun mmun commented Jan 24, 2016

Fixes #12475.

UPDATE: This reasoning isn't correct. See #12860 (comment).

This commit restores the contract of ArrayProxy content being a simple property instead of a computed property. This prevents accidental clobberings such as in ember-data:

https://github.com/emberjs/data/blob/v2.3.3/addon/-private/system/record-arrays/record-array.js#L44

This commit also removes a private hook arrangedContentArrayWillChange and partially removes another private hook arrangedContentWillChange. In the interest of keeping this bugfix commit minimal, we will continue removing the will* hooks on canary.

As the bug was caused by ember-data clobbering a descriptor, there is no simple way to test this within ember. I would recommend adding an integration test to ember-data that covers this case.

cc @krisselden @stefanpenner @ef4 @fivetanley

Fixes emberjs#12475.

This commit restores the contract of ArrayProxy content being a simple
property instead of a computed property. This prevents accidental
clobberings such as in ember-data:

https://github.com/emberjs/data/blob/v2.3.3/addon/-private/system/record-arrays/record-array.js#L44

This commit also removes a private hook `arrangedContentArrayWillChange`.
In the interest of keeping this bugfix commit minimal, we will continue
removing the will* hooks on canary.
@ef4
Copy link
Contributor

ef4 commented Jan 24, 2016

We still don't have a root cause analysis of this bug. I suspect it is revealing a problem deeper in ember-metal. Maybe one of the ones @stefanpenner uncovered recently.

[Edit to add: I was referring to https://github.com//pull/12832, but it's unclear to me whether there are any real remaining bugs there once we stopped trolling ourselves with array prototype extension issues in the tests themselves.]

CP clobbering should cause the arrangedContentArrayWillChange and arrangedContentWillChange hooks to not fire, but this PR removes those hooks anyway. So what was it about the presence of the CP that caused dropped events?

@mmun
Copy link
Member Author

mmun commented Jan 24, 2016

Should we hold off on merging this until we've attempted to find the root cause? I'm looking now :)

@mmun
Copy link
Member Author

mmun commented Jan 24, 2016

@ef4: Actually, I got it backwards. The problem is not with clobbering. In fact, the places where ember-data clobbers the content descriptor actually work around the bug :P. The bug occurs when the content descriptor is not clobbered! For example, with the PromiseArray in ember-data.

The bug seems to occur in the call to this.arrangedContentArrayWillChange(...). When I removed this line my app started working. I haven't looked into why exactly this breaks, but I also don't really care too much because it's only to support before observers.

@stefanpenner
Copy link
Member

I would like to review this. But won't have time until Monday

@rwjblue
Copy link
Member

rwjblue commented Jan 26, 2016

@stefanpenner - Have you had a chance to review?

@mmun
Copy link
Member Author

mmun commented Jan 26, 2016

@rwjblue: Once @stefanpenner signs off I will update the commit message. It does not have the correct reasoning.

@stefanpenner
Copy link
Member

I haven't looked into why exactly this breaks, but I also don't really care too much because it's only to support before observers.

I would like to know why this breaks. Unfortunately I didn't end up having time tonight.
To accept this bugfix, we should have a corresponding regression test case. Something codifying @mmun's scenario, so future refactoring take it into account.

@stefanpenner
Copy link
Member

we should also mark arrangedContent as something that will be deprecated

@mmun mmun changed the title [BUGFIX release] ArrayProxy should not be a computed property [BUGFIX release] ArrayProxy#content should not be a computed property Jan 28, 2016
@mmun mmun closed this Feb 2, 2016
@mmun
Copy link
Member Author

mmun commented Feb 3, 2016

The old array proxy set up before and "after" observers for arrangedContent. These two observers eventually call Array#arrayContentWillChange and Array#arrayContentDidChange respectively. These two Array methods are used to send array events (the events you are subscribing to when you use array.addArrayObserver). They also have the side effect of tearing down / setting up each proxy observers respectively. See here and here.

Consequently, every call to arrayContentWillChange is meant to be followed by a call to arrayContentDidChange so that the each proxy can setup observers on the new content array.

The ArrayProxy bug occurred when we moved the logic out of a before observer and into a setter.

The problem with this is that setters are always called, but before observers are only called if they are being watched. Since we left the "after" observer logic the way it was, this caused an asymmetry in calls to arrayContentWillChange and arrayContentDidChange.

As stated earlier, the extra call to arrayContentWillChange caused the each proxy to try remove observers from each of its items, which caused watch counts to needless decrement, which in turn caused the watcher count to hit 0 prematurely and thus prevent observers from firing.

Sorry for the messy explanation. It's a tricky bug to explain. Especially at 4 AM 🌝

@rwjblue
Copy link
Member

rwjblue commented Feb 3, 2016

@mmun - Thanks for the detailed walk through!

@ef4
Copy link
Contributor

ef4 commented Feb 3, 2016

Thanks @mmun 👏

@rwjblue
Copy link
Member

rwjblue commented Feb 3, 2016

@mmun - Can you PR the fix from 7552f6f with [BUGFIX release] so we can get the fix released?

@rwjblue
Copy link
Member

rwjblue commented Feb 5, 2016

For those interested, this should end up in 2.4.0-beta.2 and 2.3.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Computed Properties broken with @each in 2.1.0
4 participants